<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,viewport-fit=cover">
    <title>WeUI</title>
    <link rel="stylesheet" href="../css/weui.css"/>
    <link rel="stylesheet" href="../css/perInfo.css"/>
    <script src="../js/main.js"></script>
    <script src="../js/jquery-2.1.1.min.js"></script>
    <script src="../js/jquery.form.min.js"></script>
    <script src="../layer/layer.js"></script>
    <title>注册</title>
</head>

<body>

<div id="d" style="padding-bottom:10%;width:100%;height:0;margin-top: 1rem;background-color: black;margin-top: 0px;">
    <div style="width:70%;margin:auto auto;">
        <img src="../img/index/top.png" style="height: auto;width:100%; margin:auto auto;"/>
    </div>


</div>


<form id="userForm" method="post">


    <div class="weui-cells weui-cells_form">
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">姓名</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" type="text" name="name" placeholder="请输入姓名">
            </div>
        </div>


        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">性别</label></div>
            <div class="weui-cell__bd">
                男<input type="radio" value="男"  name="sex"/>&nbsp;&nbsp;女<input type="radio" value="女" name="sex"/>
            </div>
        </div>


        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">照片</label></div>
            <div class="weui-cell__bd">
                <input type="file" name="pic" onchange="setImgNoNull()"/>
            </div>
        </div>

        <input type="hidden" name="img">


        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">职称</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" name="title" type="text" placeholder="请输入职称">
            </div>
        </div>


        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">学位</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" name="degree" type="text" placeholder="请输入学位">
            </div>
        </div>

        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">所在部门</label></div>
            <div class="weui-cell__bd">
                <select class="weui-select" name="cid">

                </select>
            </div>
        </div>

        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">专业领域</label></div>
            <div class="weui-cell__bd">
                <select class="" name="id">

                </select>
                <select class="" name="fid">

                </select>
            </div>
        </div>


        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">联系方式</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" name="phone" type="text" placeholder="请输入联系方式">
            </div>
        </div>

        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">电子邮箱</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" name="email" type="email" placeholder="请输入电子邮箱">
            </div>
        </div>

        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">基本简介</label></div>
            <div class="weui-cell__bd">
                <textarea  name="info" class="weui-textarea"  rows="3"  placeholder="请输入基本简介"></textarea>
            </div>
        </div>
    </div>


    <div class="weui-btn-area">
        <input type="submit" class="weui-btn weui-btn_primary" id="showTooltips" value="提交">
    </div>
</form>
<script>
    $.ajaxSetup({
        xhrFields: {
            withCredentials: isCrossDomain
        }
    });
    $(function () {
        $("select[name='id']").change(function () {
            var id = $("select[name='id'] option:selected").val();
            $.post(mainurl+"get/twoFieldList",{id:id},function (data) {
                $("select[name='fid'] option").remove();
                if(checkData(data)){
                    for(i=0; i<data.data.length; i++) {
                        var d = data.data[i];
                        $("select[name='fid']").append(
                            "<option value="+d.id+">"
                            + d.field + "</option>");
                    }
                    $("select[name='fid'] option[value='"+dat.fid+"']").prop("selected",true);
                }
            });
        });


        // $.get(mainurl+"get/colleges",function (data) {
        //     if(checkData(data)){
        //         for(i=0; i<data.data.length; i++) {
        //             var d = data.data[i];
        //             $("select[name='cid']").append(
        //                 "<option value="+d.cid+">"
        //                 + d.college + "</option>");
        //         }
        //         $("select[name='cid'] option[value='5']").prop("selected",true);
        //     }
        // });
        $.get(mainurl+"v03/getUserInfo",function (data) {
            if(checkData(data)){
                var dat = data.data;
                if(dat!=null){

                    $.get(mainurl+"get/colleges",function (data) {
                        if(checkData(data)){
                            for(i=0; i<data.data.length; i++) {
                                var d = data.data[i];
                                $("select[name='cid']").append(
                                    "<option value="+d.cid+">"
                                    + d.college + "</option>");
                            }
                            $("select[name='cid'] option[value='"+dat.cid+"']").prop("selected",true);
                        }
                    });

                    $.get(mainurl+"get/oneFieldList",function (data) {
                        if(checkData(data)){
                            for(i=0; i<data.data.length; i++) {
                                var d = data.data[i];
                                $("select[name='id']").append(
                                    "<option value="+d.id+">"
                                    + d.field + "</option>");
                            }
                            $("select[name='id'] option[value='"+dat.id+"']").prop("selected",true);
                        }
                    });

                    if(dat.id != null){
                        $.post(mainurl+"get/twoFieldList",{id:dat.id},function (data) {
                            if(checkData(data)){
                                for(i=0; i<data.data.length; i++) {
                                    var d = data.data[i];
                                    $("select[name='fid']").append(
                                        "<option value="+d.id+">"
                                        + d.field + "</option>");
                                }
                                $("select[name='fid'] option[value='"+dat.fid+"']").prop("selected",true);
                            }
                        });
                    }
                    setDataByName(dat);
                }
            }
        });

        var options = {
            // 规定把请求发送到那个URL
            url: mainurl+"v03/setUser",
            // 请求方式
            type: "post",
            // 服务器响应的数据类型
            dataType: "json",
            beforeSubmit: function (formData, jqForm, options) {


                for(i=0; i<formData.length; i++) {
                    if(formData[i].name=='pic'){
                        continue;
                    }
                    if(formData[i].value==''){
                        warnInfo("参数不能为空");
                        return false;
                    }
                }
                return true;
            },
            // 请求成功时执行的回调函数
            success: function(data, status, xhr) {
                if(checkData(data)) {
                    successInfo("修改成功");
                    window.history.back(-1);
                }
            }
        };
        $("#userForm").ajaxForm(options);
    });
</script>

</body>
</html>